// pages/order/order.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		uid: "",
		data: '',
		pg: 1,
		cs: 4,
		http: getApp().globalData.map,
		pd: false,
		xs: 0,
		data: [],
		sta: false,
		nsta: 0,
		time1: '',
		time2: '',
		name: '',
		order: '',
		moblie: "",
		type: ''
	},
	bindTimeChange1: function(e) {
		this.setData({
			time1: e.detail.value,
		})
	},
	bindTimeChange2: function(e) {
		this.setData({
			time2: e.detail.value,
		})
	},
	onShow: function() {
		wx.request({
			url: getApp().globalData.http + 'action=getServerType',
			success: (e) => {
				this.setData({
					lei: e.data.data
				})
			}
		})
		wx.getStorage({
			key: 'uid',
			success: (e) => {
				this.setData({
					data:[],
					uid: e.data
				})
				this.tj()
			}
		})
	},
	tj() {
		let nan = this.data.data
		wx.showToast({
			title: '加载中',
			icon: 'loading'
		});
		let a = ''
		let that = this
		if (this.data.cs == 0) {
			a = getApp().globalData.chang + 'action=jyorder&sta=' + that.data.nsta + '&uid=' + that.data.uid.uid + '&pg=' +
				that.data.pg + '&startTime=' + that.data.time1 + '&endTime=' + that.data.time2 + '&type=' + that.data.type +
				'&mobile=' +
				that.data.moblie
		} else if (this.data.cs == 1) {
			a = getApp().globalData.chang + 'action=serverOrder&sta=' + that.data.nsta + '&uid=' + that.data.uid.uid + '&pg=' +
				that.data.pg + '&startTime=' + that.data.time1 + '&endTime=' + that.data.time2 + '&serverType=' + that.data.type +
				'&mobile=' +
				that.data.moblie
		} else if (this.data.cs == 3) {
			a = getApp().globalData.chang + 'action=shopserverOrder&sta=' + that.data.nsta + '&uid=' + that.data.uid.uid +
				'&pg=' +
				that.data.pg + '&startTime=' + that.data.time1 + '&endTime=' + that.data.time2 + '&goodName=' + that.data.type +
				'&mobile=' +
				that.data.moblie
		} else if (this.data.cs == 4) {
			a = getApp().globalData.chang + 'action=goodOrder&sta=' + that.data.nsta + '&uid=' + that.data.uid.uid + '&pg=' +
				that.data.pg + '&startTime=' + that.data.time1 + '&endTime=' + that.data.time2 + '&orderCode=' + that.data.order +
				'&goodName=' +
				that.data.name + '&mobile=' + that.data.moblie
		}
		wx.request({
			url: a,
			success: (e) => {
				console.log(e)
				let a = []
				if (this.data.cs == 0) {
					e.data.data.forEach(function(item, index) {
						if (item.Status == 2) {
							a.push('待处理')
						} else if (item.Status == 3) {
							a.push('已完成')
						}
						nan.push(item)
					})
				} else if (this.data.cs == 1) {
					e.data.data.forEach(function(item, index) {
						let c = []
						item.ServerType.forEach(function(item, index) {
							c.push(item.Tname)
						})
						a.push(c.join())
						nan.push(item)
					})
				} else if (this.data.cs == 3) {
					e.data.data.forEach(function(item, index) {
						nan.push(item)
					})
				}else{
					e.data.data.forEach(function(item, index) {
						nan.push(item)
					})
				}
				if (e.data.data.length < 15) {
					this.setData({
						pd: true
					})
				}
				if (e.data.data.length == 0) {
					this.setData({
						xs: 1
					})
				} else {
					this.setData({
						xs: 0
					})
				}
				this.setData({
					data: nan,
					zt: a
				})
				wx.hideToast();
			}
		})
	},
	ovo() {
		if (this.data.pd == 'false') {
			let a = this.data.pg + 1
			this.setData({
				pg: a
			})
			this.tj()
		}
	},
	cut(e) {
		this.setData({
			cs: e.currentTarget.dataset.id,
			data: [],
			pg:1,
			type: ''
		})
		this.tj()
	},
	dj(e) {
		wx.navigateTo({
			url: '../goods/goods?id=' + e.currentTarget.dataset.id + '&L=3'
		})
	},
	qrsh(e) {
		wx.navigateTo({
			url: '../goods/goods?id=' + e.currentTarget.dataset.id + '&L=3'
		})
	},
	yysure(e) {
		wx.request({
			url: getApp().globalData.chang + 'action=doServerOrder&id=' + e.currentTarget.dataset.id,
			success: (e) => {
				console.log(e)
				this.tj()
			}
		})
	},
	sure() {
		this.setData({
			data: [],
			sta1:false
		})
		this.tj()
	},
	dh(e) {
		wx.makePhoneCall({
			phoneNumber: e.currentTarget.dataset.id //仅为示例，并非真实的电话号码
		})
	},
	sx() {
		this.setData({
			sta: true
		})
	},
	sc() {
		this.setData({
			sta1: true
		})
	},
	nasa(e) {
		this.setData({
			nsta: e.currentTarget.dataset.id,
			sta: false,
			data: [],
		})
		this.tj()
	},
	none() {
		this.setData({
			sta: false,
			sta1: false
		})
	},
	name(e) {
		this.setData({
			name: e.detail.value
		})
	},
	moblie(e) {
		this.setData({
			moblie: e.detail.value
		})
	},
	order(e) {
		this.setData({
			order: e.detail.value
		})
	},
	type(e) {
		this.setData({
			type: e.currentTarget.dataset.id
		})
	},
	cz() {
		this.setData({
			order: '',
			moblie: '',
			name: '',
			time2: '',
			time1: '',
			type:''
		})
	}
})
